package com.hs.sfzy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hs.sfzy.entity.Reply;
import com.hs.sfzy.mapper.ReplyMapper;
import com.hs.sfzy.mapper.UserMapper;
import com.hs.sfzy.service.ReplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Date;
import java.util.List;

/**
 * @ClassName ReplyServiceImpl
 * @Description TODO
 * @Author zgy
 * @Date 2024年10月24日 17:22
 * @Version 1.0
 */
@Service
public class ReplyServiceImpl implements ReplyService {
    @Autowired
    private ReplyMapper replyMapper;
    @Autowired
    private UserMapper userMapper;
    @Override
    public int insert(Reply reply) {
        reply.setCreateTime(new Date());
        return replyMapper.insert(reply);
    }

    @Override
    public int delete(int id) {
        return replyMapper.delete(id);
    }

    @Override
    public int update(Reply reply) {
        return replyMapper.update(reply);
    }

    @Override
    public List<Reply> selectAll(Reply reply) {
        return replyMapper.selectAll(reply);
    }

    @Override
    public Reply selectById(int id) {
        return replyMapper.selectById(id);
    }

    @Override
    public PageInfo<Reply> selectByPageInfo(int pageNum, int pageSize, Reply reply) {
        PageHelper.startPage(pageNum,pageSize);
        List<Reply> list = replyMapper.selectAll(reply);
        for (Reply reply1 : list) {
            reply1.setUser(userMapper.getUserById(reply1.getUserId()));
        }
        PageInfo<Reply> pageInfo = new PageInfo<Reply>(list);
        return pageInfo;
    }

    @Override
    public List<Reply> selectByQuestionId(Long questionId) {
        List<Reply> list = replyMapper.selectByQuestionId(questionId);
        for (Reply reply : list) {
            reply.setUser(userMapper.getUserById(reply.getUserId()));
        }
        return list;
    }

    @Override
    public List<Reply> findById(Long userId) {
        return replyMapper.findById(userId);
    }


}
